package Servlet;

import Dao.JournalismMapper;
import Pojo.NewInfo;
import Service.ViceCheck;
import Service.ViceFindInfo;
import org.apache.log4j.Logger;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
 
@WebServlet("/Updata")
public class Updata extends HttpServlet {
//    根据id查用户信息
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String id = req.getParameter("id");
        ViceFindInfo viceFindInfo = new ViceFindInfo();
        NewInfo idnewinfo = viceFindInfo.findidinfo(id);
        req.getSession().setAttribute("idnewinfo",idnewinfo);
        resp.getWriter().print(req.getContextPath()+"/Update.jsp");
    }

//    修改新闻
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        ViceFindInfo viceFindInfo = new ViceFindInfo();
        String idd= req.getParameter("idd");
        String title= req.getParameter("title");
        String simply= req.getParameter("simply");
        String content= req.getParameter("content");
        String type= req.getParameter("type");
        String time= req.getParameter("time");


        if(viceFindInfo.updatanew(idd,title,simply,content,type,time)>0){
            ViceCheck viceCheck = new ViceCheck();
//            修改新闻后进行刷新
            List<NewInfo> newInfo = viceCheck.findinfo(1);
            req.getSession().removeAttribute("newInfo");
            req.getSession().setAttribute("newInfo",newInfo);
            resp.sendRedirect(req.getContextPath()+"/infomanager.jsp");
        }
    }
}
